﻿@using System.Data;
@using DTcms.Common;
@using DTcms.Model;
@{
   Layout = "~/Areas/admin/Views/Shared/_LayoutList.cshtml";
    ViewBag.Title = "Oauth列表";
    DataTable list = ViewData["list"] as DataTable;
    List<SelectListItem> siteListItems = ViewData["siteListItems"] as List<SelectListItem>;
    int site_id = (int)ViewBag.SiteId;
}

@section HeaderContent{
   <script>
      function getQueryParam() {
         var text = $("#txtKeywords").val();
         var pagesize = $("#txtPageNum").val();
         var siteId = $("#ddlSiteId").val();
         return "keywords=" + text + "&pagesize=" + pagesize + "&site_id=" + siteId;
      }
      //查询数据
      function search() {
         document.location = "index?" + getQueryParam();
      }

      //ExePostBack回调函数
      function __doPostBack(objId) {
         if (objId == "btnDelete") {
            submitdelete();
         }
      }
      
      //批量删除
      function submitdelete() {
         var $row = $("#ltable tr:gt(0)");
         var json = { list: [] };
         $($row).each(function (i, item) {
            if ($(item).find("input:checkbox").prop("checked")) {
               var id = $(item).find("td:eq(0)").find("label:eq(0)").text();
               var obj = { id: id };
               json.list.push(obj);
            }
         });
         $.ajax({
            url: "SubmitDelete?" + getQueryParam(),
            type: "POST",
            dataType: "html",
            data: "json=" + JSON.stringify(json),
            success: function (data) {
               eval(data);
            },
            error: function () {
               alert("删除数据失败!");
            }
         });
      }

      //保存排序
      function submitSave() {
         //遍历表格行设置Json数据
         var $tr = $("#ltable tr:gt(0)");
         var json = { list: [] };
         $($tr).each(function (i, item) {
            var id = $(item).find("td:eq(0)").find("label:eq(0)").text();
            var sortId = $(item).find(".sort").val();
            var obj = { id: id, sortId: sortId };
            json.list.push(obj);
         });
         // 提交保存排序字段
         $.ajax({
            url: "SubmitSave?" + getQueryParam(),
            type: "POST",
            dataType: "html",
            data: "json=" + JSON.stringify(json),
            success: function (data) {
               eval(data);
            },
            error: function(){
               alert("保存排序失败!");
            }
         });
      }
   </script>
}

<form id="form1" runat="server">
<!--导航栏-->
<div class="location">
  <a href="javascript:history.back(-1);" class="back"><i class="iconfont icon-up"></i><span>返回上一页</span></a>
  <a href="../../center/index"><i class="iconfont icon-home"></i><span>首页</span></a>
  <i class="arrow iconfont icon-arrow-right"></i>
  <span>会员设置</span>
  <i class="arrow iconfont icon-arrow-right"></i>
  <span>OAuth列表</span>
</div>
<!--/导航栏-->

<!--工具栏-->
<div id="floatHead" class="toolbar-wrap">
  <div class="toolbar">
    <div class="box-wrap">
      <a class="menu-btn"><i class="iconfont icon-more"></i></a>
      <div class="l-list">
        <ul class="icon-list">
          <li><a href="../oauth_app_list/index"><i class="iconfont icon-app"></i><span>应用管理</span></a></li>
          <li><a href="../user_oauth/index"><i class="iconfont icon-user"></i><span>授权管理</span></a></li>
          <li><a href="../site_oauth_edit/index?action=@DTEnums.ActionEnum.Add"><i class="iconfont icon-close"></i><span>新增</span></a></li>
          <li><a href="javascript:;" onclick="javascript:submitSave();"><i class="iconfont icon-save"></i><span>保存</span></a></li>
          <li><a href="javascript:;" onclick="checkAll(this);"><i class="iconfont icon-check"></i><span>全选</span></a></li>
          <li><a href="javascript:;"  id="btnDelete" onclick="ExePostBack('btnDelete');"><i class="iconfont icon-delete"></i><span>删除</span></a></li>
        </ul>
        <div class="menu-list">
          <div class="rule-single-select">
            @Html.DropDownList("ddlSiteId", new SelectList(siteListItems, "Value", "Text", site_id.ToString()), new { onchange = "search();" })
          </div>
        </div>
      </div>
      <div class="r-list">
        <input type="text" id="txtKeywords" class="keyword" value="@ViewBag.Keywords" />
        <a href="javascript:search();" id="lbtnSearch" class="btn-search"><i class="iconfont icon-search"></i></a>
      </div>
    </div>
  </div>
</div>
<!--/工具栏-->

<!--列表-->
<div class="table-container">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="ltable" id="ltable">
  <tr>
    <th width="8%">选择</th>
    <th align="left" width="8%">所属应用</th>
    <th align="left">标题</th>
    <th align="left" width="15%">所属站点</th>
    <th align="left" width="65">排序</th>
    <th align="left" width="16%">时间</th>
    <th width="10%">操作</th>
  </tr>
@foreach(DataRow dr in list.Rows){
  <tr>
    <td align="center">
      <span class="checkall" style="vertical-align:middle"><input type="checkbox" /></span>
      <label style="display:none">@dr["id"]</label>
    </td>
    <td><img src="@dr["img_url"]" title="@dr["ptitle"]" /></td>
    <td><a href="../site_oauth_edit/index?action=@DTEnums.ActionEnum.Edit&id=@dr["id"]">@dr["title"]</a></td>
    <td>@(new DTcms.BLL.sites().GetTitle(Utils.StrToInt(dr["site_id"].ToString(),0)))</td>
    <td><input type="text" id="txtSortId" class="sort" value="@dr["sort_id"]" onkeydown="return checkNumber(event);" /></td>
    <td>@(string.Format("{0:g}",dr["add_time"]))</td>
    <td align="center"><a href="../site_oauth_edit/index?action=@DTEnums.ActionEnum.Edit&id=@dr["id"]">修改</a></td>
  </tr>
}
@if (list.Rows.Count == 0) {
   <tr><td align="center" colspan="7">暂无记录</td></tr>
}
</table>
</div>
<!--/列表-->

<!--内容底部-->
<div class="line20"></div>
<div class="pagelist">
  <div class="l-btns">
    <span>显示</span>
     <input type="text" id="txtPageNum" class="pagenum" value="@ViewBag.PageSize" onkeydown="return checkNumber(event);" onchange="search();" />
     <span>条/页</span>
  </div>
  <div class="default">@Html.Raw(ViewBag.PageContent)</div>
</div>
<!--/内容底部-->

</form>